Disable color for formatter file output#1886
Open
StantonMatt wants to merge 1 commit into
Open
Conversation
3ea5cde to
b074398
Compare
Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>
b074398 to
1ed40df
Compare
There was a problem hiding this comment.
Pull request overview
Updates console formatter coloring so default ANSI color behavior is determined per-formatter from its own output stream (TTY vs --out file), while still honoring explicit --color / --no-color.
Changes:
- Added per-formatter color decision logic in
Consolevia a scopedwith_formatter_coloringwrapper. - Persisted CLI
--[no-]colorinto parsed options so formatter instances can detect explicit overrides. - Added specs and changelog entry covering the new default behavior for
--out.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/cucumber/formatter/console_spec.rb | Adds coverage for default/per-output coloring behavior and step-arg formatting. |
| lib/cucumber/formatter/console.rb | Scopes global ANSIColor state to a formatter call based on destination and explicit options. |
| lib/cucumber/formatter/console_counts.rb | Stores @config so Console coloring logic can inspect formatter output/options. |
| lib/cucumber/cli/options.rb | Saves parsed --[no-]color into @options[:color] in addition to setting global state. |
| CHANGELOG.md | Documents the new default: no ANSI color when console output is written via --out. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+35
to
+40
| it 'uses color by default when the formatter output is a tty' do | ||
| @io = instance_double(IO, tty?: true) | ||
| @options = {} | ||
|
|
||
| expect(format_string('undefined', :undefined)).to include("\e[33m") | ||
| end |
Comment on lines
+49
to
+54
| it 'allows explicit color to override the formatter output destination' do | ||
| @io = instance_double(File, tty?: false) | ||
| @options = { color: true } | ||
|
|
||
| expect(format_string('undefined', :undefined)).to include("\e[33m") | ||
| end |
Comment on lines
+236
to
+242
| def with_formatter_coloring | ||
| original_coloring = Cucumber::Term::ANSIColor.coloring? | ||
| Cucumber::Term::ANSIColor.coloring = formatter_coloring? | ||
| yield | ||
| ensure | ||
| Cucumber::Term::ANSIColor.coloring = original_coloring | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Addresses the default formatter-output behavior from #1288.
Console formatters now decide default coloring from their own output stream. That means a command like
--format pretty --out pretty.txt --format progresscan keep the progress formatter colored on a TTY while writing plain text topretty.txt.Explicit
--colorand--no-colorstill override the output destination.Type of change
Checklist:
bundle exec rubocopreports no offensesChecked locally:
bundle exec rspecbundle exec cucumber --publish-quietbundle exec rspec spec/cucumber/formatter/console_spec.rb spec/cucumber/formatter/console_counts_spec.rb spec/cucumber/cli/configuration_spec.rbbundle exec rspec compatibility/spec -f dbundle exec rubocop